
<html>
<head>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<style>
.inputa{
	width:40%;
}
.inputb{
	width:40%;
}
.inlineDiv{
    display: inline-block;
}
</style>

</head>
<body>
    <a href="index.html">计算器</a>
<div class="divbg"  >
    <textarea id="text1" rows="20" cols="30" onblur="onText1Blur()"></textarea>
    <textarea id="text2" rows="20" cols="30"></textarea>
    <textarea id="text3" rows="20" cols="30"></textarea>
</div>

<input type="text" id="regexText" style="width:600px;" placeholder="请输入正则" /><br>
<input type="text" id="replaceText" style="width:600px;" placeholder="请输入替换结果" /><br>
<input type="button" onclick="regexClick()" value="正则提取" />
<input type="button" onclick="replaceClick()" value="正则拼接" />
<input type="button" onclick="removeBlankClick()" value="去掉空行" />
<input type="button" onclick="ouToIn()" value="结果作为输入" />
<br>
注：正则表达式需加括号，$1代表匹配的字符；<br>
<div class="inlineDiv">
    onStart(text)<br>
    <textarea id="startText" rows="10" cols="30" placeholder="请输入自定义方法"></textarea>
</div>
<div class="inlineDiv">
    onRow(sourceRow,repRow)<br>
    <textarea id="rowText" rows="10" cols="30" placeholder="请输入自定义方法"></textarea>
</div>
<div class="inlineDiv">
    onEnd(text,endText)<br>
    <textarea id="endText" rows="10" cols="30" placeholder="请输入自定义方法"></textarea>
</div>
<br>
<input type="button" onclick="advanceReplace()" value="执行" />
<input type="button" onclick="addfa1()" value="方案一" />
<input type="button" onclick="addfa2()" value="方案二 序列" />
<input type="button" onclick="addfa3()" value="方案三" />
<input type="button" onclick="addfa4()" value="方案四" />



<script >
function regexClick() {
    let text = $('#text1').val();
    let regexText = $('#regexText').val();
    let replaceText = $('#replaceText').val();
    let arr = text.split(/[\r\n]/);
    let ret = [];

    for (let index=0; index < arr.length; index++) {
        const elem = arr[index];
        let regExp = new RegExp(regexText, 'g');
        let s1 = elem.replace(regExp,"$1");
        ret.push(s1);
    }
    var s = ret.join("\r\n");
    $('#text2').val(s);
}
function replaceClick() {
    let text = $('#text1').val();
    let regexText = $('#regexText').val();
    let replaceText = $('#replaceText').val();
    let arr = text.split(/[\r\n]/);
    let ret = [];
    let regExp = new RegExp(regexText, 'i');
    for (let index=0; index < arr.length; index++) {
        const elem = arr[index];
        let s1 = elem.replace(regExp,replaceText);
        ret.push(s1);
    }
    var s = ret.join("\r\n");
    $('#text3').val(s);
}
function removeBlankClick() {
    let text = $('#text1').val();
    let arr = text.split(/[\r\n]/);
    let ret = [];
    for (let index=0; index < arr.length; index++) {
        const elem = arr[index];
        if(!isBlank(elem)){
            ret.push(elem);
        }
    }
    var s = ret.join("\r\n");
    $('#text1').val(s);
}
function ouToIn() {
    let text = $('#text3').val();
    $('#text1').val(text);
}
function cc(){

	console.log($('.divbg'));
	$('.divbg').each(function(i,item){

		var bdsValue = $(item).find('#bds').val();
		bdsValue = bdsValue.replace(/,/g, "");
		var val2 = eval(bdsValue);
		$(item).find('#label2').val(val2);
	});
	
}
function isBlank(strIn) {
    if (strIn === undefined) {
        return true;
    } else if (strIn == null) {
        return true;
    } else if (strIn == "") {
        return true;
    }
    var trim = strIn.trim();
    if (trim == "") {
        return true;
    }
    return false;
}

function advanceReplace() {
    let text = $('#text1').val();
    let regexText = $('#regexText').val();
    let replaceText = $('#replaceText').val();
    let startText = $('#startText').val();
    let rowText = $('#rowText').val();
    let endFunText = $('#endText').val();
    let arr = text.split(/[\r\n]/);
    let ret = [];
    let regExp = new RegExp(regexText, 'i');
    if(!isBlank(startText)){
        eval(startText);
    }


    for (let index=0; index < arr.length; index++) {
        const elem = arr[index];
        let s1 = elem.replace(regExp,replaceText);
        var s2 = s1;
        if(!isBlank(rowText)){
            var s2 = eval("(function (sourceRow,repRow) {"+rowText+"})('"+elem+"','"+s1+"')");
        }
        ret.push(s2);
    }
    var s = ret.join("\r\n");
    if(!isBlank(endFunText)){
        let endText = s;
        eval(endFunText);
    }

    $('#text3').val(s);
}
function onText1Blur() {
    let text = $('#text1').val();
    let arr = text.split(/[\r\n]/);
    let maxLength = 0;
    for (let index=0; index < arr.length; index++) {
        const elem = arr[index];
        var length = elem.length;
        var s = elem.replace(/\t/g,'');
        var number = length- s.length;
        length += number*8;
        if(length>maxLength) maxLength = length;

    }
    if(maxLength<30) maxLength = 30;
    if(maxLength>600)  maxLength = 600;
    $('#text1').prop("cols",maxLength);
}
function addfa1() {
    $('#text1').val("\t\t<result column=\"l_amount\" property=\"amount\"/>\n" +
        "\t\t<result column=\"en_balance\" property=\"enBalance\"/>\n" +
        "\t\t<result column=\"en_fact_price\" property=\"enFactPrice\"/>\n" +
        "\t\t<result column=\"l_basecombi_id\" property=\"basecombiId\"/>\n" +
        "\t\t<result column=\"vc_inter_code\" property=\"vcInterCode\"/>\n" +
        "\t\t<result column=\"vc_fund_code\" property=\"fundCode\"/>\n" +
        "\t\t<result column=\"vc_report_code\" property=\"vcReportCode\"/>\n" +
        "\t\t<result column=\"c_approve_status\" property=\"approveStatus\"/>");
    $('#regexText').val(".*property=\"(.*)\"/>");
    $('#replaceText').val('$1');

}
function addfa2() {
    $('#startText').val('var aaa=0;');
    $('#rowText').val('aaa++;\n' +
        'return repRow+aaa;');

}
function addfa3() {

}
function addfa4() {

}
</script>
</body>
</html>